#include "hrd_coord.h"

#define SPACE_ONE_LINE 8


uint8_t HrdCoord_BitmaskToCoordinateList(hrd_bitmask_t hrd_bitmask, struct coordinate_s *dest_coordinate_list)
{
    int8_t x, y;
    struct coordinate_s coord;
    hrd_bitmask_t mask = 1;
    uint8_t coordinate_number = 0;

    for (y = 0; y < 8; y++) {
        for (x = 7; x >= 0; x--) {
            if (hrd_bitmask & mask) {
                coord.x = x;
                coord.y = y;

                dest_coordinate_list[coordinate_number++] = coord;
            }
            mask <<= 1;
        }
    }

    return coordinate_number;
}


hrd_bitmask_t HrdCoord_CoordinateToBitmask(struct coordinate_s coordinate)
{
    uint64_t mask = 1;

    return mask << (SPACE_ONE_LINE * coordinate.y + (MAX_COORDINATE - coordinate.x));
}


hrd_bitmask_t HrdCoord_CoordinateListToBitmask(struct coordinate_s *coordinate_list, uint8_t coordinate_number)
{
    uint8_t i;
    hrd_bitmask_t mask = 0;

    for (i = 0; i < coordinate_number; i++) {
        mask |= HrdCoord_CoordinateToBitmask(coordinate_list[i]);
    }

    return mask;
}
